package test2.binarySearch;

import java.math.BigDecimal;

public class Solution {

    public int search(int[] nums, int target) {
        // 在此处写入代码
        int begin = 0;
        int end = nums.length - 1;
        while (begin <= end) {
            int index = (begin + end + 1) /2;
            int num = nums[(begin + end + 1) /2];
            if (num == target) {
                return index;
            } else if (num < target) {
                begin = index + 1;
            } else {
                end = index - 1;
            }

        }
        return -1;
    }

    public int search2(int[] nums, int target) {
        // 在此处写入代码
        if (nums.length == 0) {
            return -1;
        }
        boolean left = nums[0] <= target;

        int begin = 0;
        int end = nums.length - 1;
        while (begin <= end) {
            int index = (begin + end + 1) /2;
            int num = nums[(begin + end + 1) /2];
            if (num == target) {
                return index;
            }
            if (left) {
                if ( num < target && num > nums[0]) {
                    begin = index + 1;
                } else {
                    end = index - 1;
                }
            } else {
                if (num > target && num < nums[0]) {
                    end = index - 1;
                } else {
                    begin = index + 1;
                }
            }
        }
        return -1;


    }


    public static void test() {

        double val = new BigDecimal(new BigDecimal(160.00).divide(new BigDecimal(1000)).setScale(6 , BigDecimal.ROUND_HALF_UP).doubleValue() * 1.0 * 149).setScale(2 , BigDecimal.ROUND_HALF_UP).doubleValue();
        System.out.println(val);
    }

    public static void main(String[] args) {
        test();
    }
}
